﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Reflection;
namespace MiApp {
    /// <summary>
    /// Lógica de interacción para MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {

       public  static readonly  RoutedEvent  MiEvento=  EventManager.RegisterRoutedEvent("Evt22", RoutingStrategy.Bubble,typeof(RoutedEventHandler), typeof(MainWindow));

       public static RoutedUICommand  MiComando;

       public RoutedUICommand Mc {

           get {
               return MiComando;
           }
       }

       private static readonly DependencyProperty  MyProperty;

       public int My {
           get { return (int)((object)MyProperty); }
           set {
              // Mp = (DependencyProperty)((object)value);
               SetValue(MyProperty, value);
           }
       }




         static MainWindow() {
             FrameworkPropertyMetadata fpmd = new FrameworkPropertyMetadata();
             MyProperty = DependencyProperty.Register("My", typeof(int), typeof(MainWindow), fpmd);
             MiComando = new RoutedUICommand("Mc", "Mc", typeof(MainWindow));
       RoutedEventHandler HH = new RoutedEventHandler(classHandler);
       RoutedEventHandler HH2 = new RoutedEventHandler(classHandler2);

       EventManager.RegisterClassHandler(typeof(MainWindow), MiEvento, HH, true);
       EventManager.RegisterClassHandler(typeof(MainWindow), MiEvento, HH2, false);
        
        }


         public void MyPropertyChanged(Object o, RoutedEventArgs r) {
             MessageBox.Show("Mi propiedad cambio");
         }


         CommandBinding cb = new CommandBinding();
        


        public  event RoutedEventHandler Evt {
            add { 
                this.AddHandler(MiEvento, value,true); 
            }
            remove 
            {
                this.RemoveHandler(MiEvento, value); 
            }
        
        }
        

        public MainWindow() {
           InitializeComponent();
           System.Reflection.AssemblyName aN = System.Reflection.AssemblyName.GetAssemblyName(@"C:\Users\jose.gonzalez\Documents\Visual Studio 2010\Projects\Repaso\ResourcesLib\bin\Debug\ResourcesLib.dll");
           Assembly a = Assembly.Load(aN);
           String[] str = a.GetManifestResourceNames();
           System.IO.Stream rStream = a.GetManifestResourceStream(str[0]);
         
           // cb.Command = ApplicationCommands.Close;
           //cb.CanExecute += new CanExecuteRoutedEventHandler(cb_CanExecute);
           //cb.Executed += CommandHandler;
           //this.CommandBindings.Add(cb);
            ApplicationCommands.Close.InputGestures.Add(new MouseGesture(MouseAction.LeftClick,ModifierKeys.Control));
           
        }

        void cb_CanExecute(object sender, CanExecuteRoutedEventArgs e) {
        e.CanExecute = true;
        }

        private void handler(object obj, RoutedEventArgs ar) {
            MessageBox.Show(obj.ToString());
            MessageBox.Show(ar.Source.ToString());
        }
        private void handler2(object obj, RoutedEventArgs ar) {
            MessageBox.Show(obj.ToString()+"2");
            MessageBox.Show(ar.Source.ToString() + "2");
        }

        private void Button_Click(object sender, RoutedEventArgs e) {
            RaiseEvent(new RoutedEventArgs(MiEvento));
        }

        private void Button_Click_1(object sender, RoutedEventArgs e) {
            MainWindow mm = new MainWindow();
            mm.Show();
        }

        private void Button_Click_2(object sender, RoutedEventArgs e) {
            this.Evt += handler;

        }

        private void Button_Click_3(object sender, RoutedEventArgs e) {
            
            this.Evt += handler2;
            mL.My = 23;
        }

        private static void classHandler(object o, RoutedEventArgs r){
            MessageBox.Show("Class Handler");
            r.Handled = true;
        }
        private static void classHandler2(object o, RoutedEventArgs r) {
            MessageBox.Show("Class Handler2");
            r.Handled = true;
        }

        private void MiLabel_MiMouseEvt(object sender, RoutedEventArgs e) {
            MessageBox.Show("Mi Mouse 1...");
        }

        private void MiLabel_MiMouseEvt_1(object sender, RoutedEventArgs e) {
            MessageBox.Show("Mi Mouse 2...");
        }

        private void CommandHandler(object o, ExecutedRoutedEventArgs ar) {
            this.Close();
           // ApplicationCommands.Close.Execute(null, Comm);
        }

        private void t_TextChanged(object sender, TextChangedEventArgs e) {

        }

        private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e) {
            MessageBox.Show("Se ejecuto");

        }
    }
}
